package com.ht.mt.sric.sesion;

import com.ht.mt.sric.entity.Video;
import com.ht.mt.sric.sesion.local.VideoSessionEJBBeanLocal;
import com.ht.mt.sric.sesion.remota.VideoSessionEJBBeanRemote;

import java.util.List;

import javax.annotation.Resource;

import javax.ejb.SessionContext;
import javax.ejb.Stateless;

import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless(name = "VideoSessionEJBBeanBean", mappedName = "VideoSessionEJBBeanBean")
public class VideoSessionEJBBeanBeanBean implements VideoSessionEJBBeanRemote, VideoSessionEJBBeanLocal {
    @Resource
    SessionContext sessionContext;
    @PersistenceContext(unitName = "sric_ejb")
    private EntityManager em;

    public VideoSessionEJBBeanBeanBean() {
    }

    public Video persistVideo(Video video) {
        em.persist(video);
        return video;
    }

    public Video mergeVideo(Video video) {
        return em.merge(video);
    }

    public void removeVideo(Video video) {
        video = em.find(Video.class, video.getIdVdo());
        em.remove(video);
    }

    /** <code>select o from Video o</code> */
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public List<Video> getVideoFindAll() {
        return em.createNamedQuery("Video.findAll", Video.class).getResultList();
    }
}
